﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Buy.aspx.cs" Inherits="Buy" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <link href="css/dialog.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="js/product.js" type="text/javascript"></script>
    <script src="js/jquery.query.url.js" type="text/javascript"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div class="dg_k font14" width="600">
            <ul>
              <li class="dg_k_1 white"><strong><%=m_productname %>购买</strong><a href="#"  onclick="close_all()" class="dg_close img"></a></li>
              <li class="dg_k_4"></li>
              <li class="dg_k_3">价　　格<span class="dg_jg">￥<%=m_nowprice %></span> <span class="dg_k_f dg_jg2"><%=m_price %></span> </li>
            <%--  <li class="dg_line"></li>--%>
              <%=lines1 %>
              <li class="dg_k_3" id="usertype"  runat="server">用户类型
               <%-- <input name="radio" type="radio" value="0"  checked="checked"  id="newuser"/>--%>
               <asp:RadioButton ID="newuser" runat="server" Checked="true" GroupName="UserType" 
                      AutoPostBack="True" oncheckedchanged="newuser_CheckedChanged" />
                新用户
                <%--<input name="radio" type="radio" value="1"  id="olduser"/>--%>
                  <asp:RadioButton ID="olduser" runat="server" GroupName="UserType" 
                      AutoPostBack="True" oncheckedchanged="olduser_CheckedChanged" />
                老用户</li>
           <%-- <li class="dg_line"></li>--%>
            <%=lines2 %>
			  <li class="dg_k_3" id="usercheck"  runat="server">
              <p>老用户身份验证</p>
		      <p>产品账号：<input id="txt_mobile" type="text" value="手机号/em号/rxt号" size="18" onfocus="this.select()"  onblur="if (this.value =='') this.value='手机号/em号/rxt号'"  onclick="if (this.value=='手机号/em号/rxt号') this.value=''" 
           onmouseover="this.focus()" value="手机号/em号/rxt号"/>
			</p>
            <p>
			  产品密码:
			  <input id="txt_pwd" type="password" size="18" /></p>
			  </li>
              <li class="dg_line"></li>
          <%--    <li class="dg_k_3">使用期限
                <input name="radiobutton" type="radio" value="1" checked="checked" />
                一年
                <input type="radio" name="radiobutton" value="2" />
                二年
                <input type="radio" name="radiobutton" value="3" />
                三年 </li>--%>
                  <li class="dg_k_3">使用期限
                <input name="radiobutton" type="radio" value="1" checked="checked" />
                一年
                 </li>
              <li class="dg_line"></li>
              <li class="dg_k_3">数　　量
                <input name="txt_count" type="text" value="1"  id="txt_count"/>
                件 </li>
              <li class="dg_k_4"></li>
              <li class="dg_k_2">
                <input type="button" name="Submit242" class="an3 img" value="立刻购买" onclick="GoBuy()" style="vertical-align:middle;text-align:center; cursor:pointer" />
                <input type="submit" name="Submit2222" class="an4 img" value="加入购物车" style="display:none" />
              </li>
            </ul>
        </div>
    <input id="productid" type="hidden"   value='<%=m_productid %>'/>
    </form>
    <script type="text/javascript">



//        $("#olduser").click(function () {

//            var usertype = $("#olduser").val();
//            window.parent.open_OldUser('34');
//            window.parent.close_singleW();
//            //window.location.href = "pddialog.aspx?ProductID="+34;

//        })


//        $("#newuser").click(function () {

//            var usertype = $("#newuser").val();
//            window.parent.open_NewUser('31');
//            window.parent.close_old();


//        })




//        function close_W() {

//            window.parent.close_singleW();
//        }


        function close_all() {

            window.parent.close_all();
        }

        function GoBuy() {
            var productid = $("#productid").val();
            var count = $("#txt_count").val();
            if (productid == "") {
                alert("产品编号不允许为空!");
                return false;
            }

            if (productid == "34") //一年版老用户
            {
                var mobile = $("#txt_mobile").val();
                var pwd = $("#txt_pwd").val();

                var regular = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
                if (mobile == "") {
                    alert("手机号码不能为空，请输入！");
                    $("#txt_mobile").focus();
                    return false;
                }
                mobile = jQuery.trim(mobile);
                if (!regular.test(mobile)) {
                    alert("请输入有效的手机号码！");
                    $("#txt_mobile").focus();
                    return false;
                }


                if (pwd == "") {
                    alert("密码不能为空！");
                    return false;
                }

                if (count == "") {
                    alert("商品数量不能为空！");
                    $("#txt_count").focus();
                    return false;
                }
                count = jQuery.trim(count);
                if (isNaN(count)) {
                    alert("数量输入非法！");
                    $("#txt_count").focus();
                    return false;
                }
                else {
                    if (count < 1) {
                        alert("数量不能小于1！");
                        $("#txt_count").focus();
                        return false;
                    }

                }

                //4.检测用户
                $.post("handler/CheckUser.ashx", { username: mobile, pwd: pwd }, function (data) {
                    if (isNaN(data) == false && data > 0) {
                        Add_Cart(34);
                        close_W(); //关闭
                        return false;
                    }
                    else {

                        if (data == -1) {
                            alert("用户名或密码错误！");
                            return false;
                        }
                        else {

                            alert("对不起，您之前不是益盟的付费用户，不能享受老用户优惠.");
                            close_W(); //关闭
                            return false;

                        }

                    }

                })

            }
            else {

                if (count == "") {
                    alert("商品数量不能为空！");
                    $("#txt_count").focus();
                    return false;
                }
                count = jQuery.trim(count);
                if (isNaN(count)) {
                    alert("数量输入非法！");
                    $("#txt_count").focus();
                    return false;
                }
                else {
                    if (count < 1) {
                        alert("数量不能小于1！");
                        $("#txt_count").focus();
                        return false;
                    }

                }
                Add_Cart(productid);
                close_W();
                return false;
            }
        }

        $(document).ready(function () {
            var obj = $("[name=radio]");
            Init();
        })

        function Init() {
            var ProductID = jQuery.query.get("ProductID");
            var obj = $("[name=radio]");
            //alert(ProductID);


        }

    </script>

    <script  type="text/javascript">
        function Add_Cart(id) {
            if (id == '9' || id == '10') {
                var CartType = $F("txt_CartType");
                if (CartType == "") {
                    $F("Card_id", id);
                    Div_Display();
                    $("txt_UserName").focus();
                }
                else {
                    if (id == CartType) {
                        intoCart(id);
                    }
                    else {
                        var msg = CartType == '9' ? "您需要购买360元的充值卡" : "您需要购买720元的充值卡";
                        alert(msg);
                        return;
                    }
                }
            }
            else {
                intoCart(id);
            }
        }

        function intoCart(id) {
            var uid = "";
            if (id == '9' || id == '10') {
                uid = document.getElementById("txt_UserName").value;
            }
            var count = $("#txt_count").val();
            if (count == "" || isNaN(count)) {
                alert("请输入有效的商品数量！");
                return false;
            }
            if (count < 1) {
                alert("商品数量不能小于1");
                return false;
            }

            // var _url = "http://pay.emoney.cn/shopping11.aspx";
            var _url = "http://pay.emoney.cn/_shopping11.aspx";
            _url += "?ProductID=" + id + "&UserID=" + uid + "&count=" + count;
            //           var _url = "shopping11.aspx";
            //           _url += "?ProductID=" + id + "&UserID=" + uid;
            //document.location = _url;
            window.open(_url);
        }
</script>

</body>
</html>
